

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _W25Q64_H_
#define _W25Q64_H_


/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "spi.h"
#include "stdio.h"


#define sFLASH_CMD_WRITE          0x02  /*!< Write to Memory instruction */
#define sFLASH_CMD_WRSR           0x01  /*!< Write Status Register instruction */
#define sFLASH_CMD_WREN           0x06  /*!< Write enable instruction */
#define sFLASH_CMD_READ           0x03  /*!< Read from Memory instruction */
#define sFLASH_CMD_RDSR           0x05  /*!< Read Status Register instruction  */
#define sFLASH_CMD_RDID           0x9F  /*!< Read identification */
#define sFLASH_CMD_SE             0x20  /*!< Sector Erase instruction */
#define sFLASH_CMD_BE             0xD8  /*!< Bulk Erase instruction */

#define sFLASH_WIP_FLAG           0x01  /*!< Write In Progress (WIP) flag */

#define sFLASH_DUMMY_BYTE         0xFF
#define sFLASH_SPI_PAGESIZE       0x100

#define sFLASH_M25P128_ID         0x202018
#define sFLASH_M25P64_ID          0x202017
#define sFLASH_W25Q64_ID          0xEF4017


#define WRITE_ENABLE 0x06
#define WRITE_DISABLE 0x04
#define READ_STATUS 0x05
#define READ_DATA 0x03
#define SECOT_ERASE 0x20
#define PAGE_WRITE 0x02

#define sFLASH_CS_LOW()       HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET)
#define sFLASH_CS_HIGH()      HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET)  

void sFLASH_Init(void);
void sFLASH_EraseSector(uint32_t SectorAddr);
void sFLASH_EraseBulk(void);
void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
uint32_t sFLASH_ReadID(void);
void sFLASH_StartReadSequence(uint32_t ReadAddr);

uint8_t sFLASH_ReadByte(void);
uint8_t sFLASH_SendByte(uint8_t byte);
void sFLASH_WriteEnable(void);
void sFLASH_WaitForWriteEnd(void);
uint8_t FLASH_SPI_WRData(uint8_t byte);

void W25Q64ReadBytes(uint32_t sub_addr,uint32_t num,uint8_t* p);

#ifdef __cplusplus
}
#endif

#endif /* __STM32_EVAL_SPI_FLASH_H */
